package com.iasku.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.iasku.entity.UserHomework;
import com.iasku.iaskueleclass_phone.R;

public class HomeWorkAdapter extends BaseAdapter{
    private List<UserHomework> mData;
    private LayoutInflater mInflater;
    
    public HomeWorkAdapter(Context mContext,List<UserHomework> mData){
        this.mInflater = LayoutInflater.from(mContext);
        this.mData = mData;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = this.mInflater.inflate(R.layout.homework_item,null);
            holder = new ViewHolder();
            holder.mTrueNameTv = (TextView) convertView.findViewById(R.id.tv_truename);
            holder.mWorkNameTv = (TextView) convertView.findViewById(R.id.tv_workname);
            holder.mWorkTimeTv = (TextView) convertView.findViewById(R.id.tv_worktime);
            holder.mTimeOrScoreTv = (TextView) convertView.findViewById(R.id.tv_submittime_or_sumscore);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        UserHomework work = mData.get(position);
        holder.mTrueNameTv.setText(work.getTeacher_truename());
        holder.mWorkNameTv.setText(work.getExamname());
        holder.mWorkTimeTv.setText(work.getStart_dateline());
        int status = work.getStatus();
        switch (status) {
        case 0:
            holder.mTimeOrScoreTv.setVisibility(View.GONE);
            holder.mWorkTimeTv.setText(work.getStart_dateline());
            break;

        case 1:
            holder.mTimeOrScoreTv.setVisibility(View.VISIBLE);
            holder.mTimeOrScoreTv.setText(work.getEnd_dateline());
            break;
        case 2:
            holder.mTimeOrScoreTv.setVisibility(View.VISIBLE);
            holder.mWorkTimeTv.setText(work.getEnd_dateline());
            holder.mTimeOrScoreTv.setText(work.getSumScore());
            break;
        }
        return convertView;
    }
    
    private class ViewHolder{
        TextView mTrueNameTv;
        TextView mWorkNameTv;
        TextView mWorkTimeTv;
        TextView mTimeOrScoreTv;
    }

}
